/*
 * Copyright 2007 Gergely Kis
 * Copyright 2006 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.user.client.impl;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;

/**
 * From the original GWT documentation:
 * An opaque handle to a native DOM Element. An <code>Element</code> cannot be
 * created directly. Instead, use the <code>Element</code> type when returning
 * a native DOM element from JSNI methods. An <code>Element</code> passed back
 * into JSNI becomes the original DOM element the <code>Element</code> was
 * created from, and can be accessed in JavaScript code as expected. This is
 * typically done by calling methods in the
 * {@link com.google.gwt.user.client.DOM} class.
 * 
 * 
 * <p>
 * For the GWT Server implementation:
 * This class was transformed into a marker interface. The actual implementation is the 
 * {@link com.google.gwt.user.client.impl.EventImpl} class. 
 * </p>
 */
public final class EventImpl implements Event  {
  
  private boolean cancel = false;
  
  private Element target;

  private int type;
  
  public EventImpl(int type) {
    this.type = type;
  }

  public void cancel() {
    cancel = true;
  }
  
  
  public Element getTarget() {
    return target;
  }
  
  public int getType() {
    return type;
  }

  public String getTypeString() {
    switch (type) {
      case ONBLUR:
        return "blur";
      case ONCHANGE:
        return "change";
      case ONCLICK:
        return "click";
      case ONDBLCLICK:
        return "dblclick";
      case ONFOCUS:
        return "focus";
      case ONKEYDOWN:
        return "keydown";
      case ONKEYPRESS:
        return "keypress";
      case ONKEYUP:
        return "keyup";
      case ONLOAD:
        return "load";
      case ONLOSECAPTURE:
        return "losecapture";
      case ONMOUSEDOWN:
        return "mousedown";
      case ONMOUSEMOVE:
        return "mousemove";
      case ONMOUSEOUT:
        return "mouseout";
      case ONMOUSEOVER:
        return "mouseover";
      case ONMOUSEUP:
        return "mouseup";
      case ONSCROLL:
        return "scroll";
      case ONERROR:
        return "error";
    }
    return null;
  }
  
  public boolean isCanceled() {
    return cancel;
  }
  
  public void preventDefault() {
    // TODO: Some meaningful implementation
  }
  
  public void setTarget(Element target) {
    this.target = target;
  }

}
